home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / libkcal / incidencebase.h < prev    next >
Encoding:
C/C++ Source or Header  |  2008-02-13  |  8.6 KB  |  294 lines

  1. /*
  2.     This file is part of libkcal.
  3.  
  4.     Copyright (c) 2001-2003 Cornelius Schumacher <schumacher@kde.org>
  5.     Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
  6.  
  7.     This library is free software; you can redistribute it and/or
  8.     modify it under the terms of the GNU Library General Public
  9.     License as published by the Free Software Foundation; either
  10.     version 2 of the License, or (at your option) any later version.
  11.  
  12.     This library is distributed in the hope that it will be useful,
  13.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15.     Library General Public License for more details.
  16.  
  17.     You should have received a copy of the GNU Library General Public License
  18.     along with this library; see the file COPYING.LIB.  If not, write to
  19.     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  20.     Boston, MA 02110-1301, USA.
  21. */
  22. #ifndef KCAL_INCIDENCEBASE_H
  23. #define KCAL_INCIDENCEBASE_H
  24.  
  25. #include <qdatetime.h>
  26. #include <qstringlist.h>
  27. #include <qvaluelist.h>
  28. #include <qptrlist.h>
  29.  
  30. #include "customproperties.h"
  31. #include "attendee.h"
  32.  
  33. namespace KCal {
  34.  
  35. typedef QValueList<QDate> DateList;
  36. typedef QValueList<QDateTime> DateTimeList;
  37. class Event;
  38. class Todo;
  39. class Journal;
  40. class FreeBusy;
  41.  
  42. /**
  43.   This class provides the base class common to all calendar components.
  44. */
  45. class LIBKCAL_EXPORT IncidenceBase : public CustomProperties
  46. {
  47.   public:
  48.     /**
  49.       This class provides the interface for a visitor of calendar components. It
  50.       serves as base class for concrete visitors, which implement certain actions on
  51.       calendar components. It allows to add functions, which operate on the concrete
  52.       types of calendar components, without changing the calendar component classes.
  53.     */
  54.     class Visitor
  55.     {
  56.       public:
  57.         /** Destruct Incidence::Visitor */
  58.         virtual ~Visitor() {}
  59.  
  60.         /**
  61.           Reimplement this function in your concrete subclass of IncidenceBase::Visitor to perform actions
  62.           on an Event object.
  63.         */
  64.         virtual bool visit(Event *) { return false; }
  65.         /**
  66.           Reimplement this function in your concrete subclass of IncidenceBase::Visitor to perform actions
  67.           on a Todo object.
  68.         */
  69.         virtual bool visit(Todo *) { return false; }
  70.         /**
  71.           Reimplement this function in your concrete subclass of IncidenceBase::Visitor to perform actions
  72.           on an Journal object.
  73.         */
  74.         virtual bool visit(Journal *) { return false; }
  75.         /**
  76.           Reimplement this function in your concrete subclass of IncidenceBase::Visitor to perform actions
  77.           on a FreeBusy object.
  78.         */
  79.         virtual bool visit(FreeBusy *) { return false; }
  80.  
  81.       protected:
  82.         /** Constructor is protected to prevent direct creation of visitor base class. */
  83.         Visitor() {}
  84.     };
  85.  
  86.     class Observer {
  87.       public:
  88.         virtual ~Observer() {}
  89.         virtual void incidenceUpdated( IncidenceBase * ) = 0;
  90.         virtual void incidenceUpdatedSilent( IncidenceBase * ) {};
  91.     };
  92.  
  93.     IncidenceBase();
  94.     IncidenceBase( const IncidenceBase & );
  95.     virtual ~IncidenceBase();
  96.  
  97.     IncidenceBase& operator=( const IncidenceBase &i );
  98.     bool operator==( const IncidenceBase & ) const;
  99.  
  100.     /**
  101.       Accept IncidenceVisitor. A class taking part in the visitor mechanism has to
  102.       provide this implementation:
  103.       <pre>
  104.         bool accept(Visitor &v) { return v.visit(this); }
  105.       </pre>
  106.     */
  107.     virtual bool accept(Visitor &) { return false; }
  108.  
  109.     virtual QCString type() const = 0;
  110.  
  111.     /** Set the unique id for the event */
  112.     void setUid( const QString & );
  113.     /** Return the unique id for the event */
  114.     QString uid() const;
  115.  
  116.     /** Sets the time the incidence was last modified. */
  117.     void setLastModified( const QDateTime &lm );
  118.     /** Return the time the incidence was last modified. */
  119.     QDateTime lastModified() const;
  120.  
  121.     /** sets the organizer for the event */
  122.     void setOrganizer( const Person &o );
  123.     void setOrganizer( const QString &o );
  124.     Person organizer() const;
  125.  
  126.     /** Set readonly status. */
  127.     virtual void setReadOnly( bool );
  128.     /** Return if the object is read-only. */
  129.     bool isReadOnly() const { return mReadOnly; }
  130.  
  131.     /** for setting the event's starting date/time with a QDateTime. */
  132.     virtual void setDtStart( const QDateTime &dtStart );
  133.     /** returns an event's starting date/time as a QDateTime. */
  134.     virtual QDateTime dtStart() const;
  135.     /** returns an event's starting time as a string formatted according to the
  136.      users locale settings */
  137.     virtual QString dtStartTimeStr() const;
  138.     /** returns an event's starting date as a string formatted according to the
  139.      users locale settings */
  140.     virtual QString dtStartDateStr( bool shortfmt = true ) const;
  141.     /** returns an event's starting date and time as a string formatted according
  142.      to the users locale settings */
  143.     virtual QString dtStartStr() const;
  144.  
  145.     virtual void setDuration( int seconds );
  146.     int duration() const;
  147.     void setHasDuration( bool );
  148.     bool hasDuration() const;
  149.  
  150.     /** Return true or false depending on whether the incidence "floats,"
  151.      * i.e. has a date but no time attached to it. */
  152.     bool doesFloat() const;
  153.     /** Set whether the incidence floats, i.e. has a date but no time attached to it. */
  154.     void setFloats( bool f );
  155.  
  156.     //
  157.     // Comments
  158.     //
  159.  
  160.     /**
  161.      * Add a comment to this incidence.
  162.      *
  163.      * Does not add a linefeed character.  Just appends the text as passed in.
  164.      *
  165.      * @param comment  The comment to add.
  166.      */
  167.     void addComment(const QString& comment);
  168.  
  169.     /**
  170.      * Remove a comment from the event.
  171.      *
  172.      * Removes first comment whose string is an exact match for the string
  173.      * passed in.
  174.      *
  175.      * @return true if match found, false otherwise.
  176.      */
  177.     bool removeComment( const QString& comment );
  178.  
  179.     /** Delete all comments associated with this incidence. */
  180.     void clearComments();
  181.  
  182.     /** Return all comments associated with this incidence.  */
  183.     QStringList comments() const;
  184.  
  185.     /**
  186.       Add Attendee to this incidence. IncidenceBase takes ownership of the
  187.       Attendee object.
  188.  
  189.       @param attendee a pointer to the attendee to add
  190.       @param doUpdate If true the Observers are notified, if false they are not.
  191.     */
  192.     void addAttendee( Attendee *attendee, bool doUpdate = true );
  193.     /**
  194.       Remove all Attendees.
  195.     */
  196.     void clearAttendees();
  197.     /**
  198.       Return list of attendees.
  199.     */
  200.     const Attendee::List &attendees() const { return mAttendees; };
  201.     /**
  202.       Return number of attendees.
  203.     */
  204.     int attendeeCount() const { return mAttendees.count(); };
  205.     /**
  206.       Return the Attendee with this email address.
  207.     */
  208.     Attendee *attendeeByMail( const QString & ) const;
  209.     /**
  210.       Return first Attendee with one of the given email addresses.
  211.     */
  212.     Attendee *attendeeByMails( const QStringList &,
  213.                                const QString &email = QString::null ) const;
  214.     /**
  215.       Return attendee with given uid.
  216.     */
  217.     Attendee *attendeeByUid( const QString &uid ) const;
  218.  
  219.     /**
  220.       Pilot synchronization states
  221.     */
  222.     enum { SYNCNONE = 0, SYNCMOD = 1, SYNCDEL = 3 };
  223.     /**
  224.       Set synchronisation satus.
  225.     */
  226.     void setSyncStatus( int status );
  227.     void setSyncStatusSilent( int status );
  228.     /**
  229.       Return synchronisation status.
  230.     */
  231.     int syncStatus() const;
  232.  
  233.     /**
  234.       Set Pilot Id.
  235.     */
  236.     void setPilotId( unsigned long id );
  237.     /**
  238.       Return Pilot Id.
  239.     */
  240.     unsigned long pilotId() const;
  241.  
  242.     /**
  243.       Register observer. The observer is notified when the observed object
  244.       changes.
  245.     */
  246.     void registerObserver( Observer * );
  247.     /**
  248.       Unregister observer. It isn't notified anymore about changes.
  249.     */
  250.     void unRegisterObserver( Observer * );
  251.     /**
  252.       Call this to notify the observers after the IncidenceBas object has
  253.       changed.
  254.     */
  255.     void updated();
  256.     void updatedSilent();
  257.  
  258.   protected:
  259.     /**
  260.       @copydoc
  261.       CustomProperties::customPropertyUpdated()
  262.     */
  263.     virtual void customPropertyUpdated();
  264.  
  265.     bool mReadOnly;
  266.  
  267.   private:
  268.     // base components
  269.     QDateTime mDtStart;
  270.     Person mOrganizer;
  271.     QString mUid;
  272.     QDateTime mLastModified;
  273.     Attendee::List mAttendees;
  274.     QStringList mComments;
  275.  
  276.     bool mFloats;
  277.  
  278.     int mDuration;
  279.     bool mHasDuration;
  280.  
  281.     // PILOT SYNCHRONIZATION STUFF
  282.     unsigned long mPilotId;                         // unique id for pilot sync
  283.     int mSyncStatus;                      // status (for sync)
  284.  
  285.     QPtrList<Observer> mObservers;
  286.  
  287.     class Private;
  288.     Private *d;
  289. };
  290.  
  291. }
  292.  
  293. #endif
  294.